package com.ruoyi.web.controller.admin;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.HospitalSubscribeProject;
import com.ruoyi.system.domain.HospitalSubscribeScheduleTemplate;
import com.ruoyi.system.mapper.HospitalSubscribeProjectMapper;
import com.ruoyi.system.service.IHospitalSubscribeProjectService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HospitalSubscribeSetMeal;
import com.ruoyi.system.service.IHospitalSubscribeSetMealService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 体检套餐Controller
 * 
 * @author ruoyi
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/admin/meal")
public class HospitalSubscribeSetMealAdminController extends BaseController
{
    @Autowired
    private IHospitalSubscribeSetMealService hospitalSubscribeSetMealService;

    @Autowired
    private IHospitalSubscribeProjectService iHospitalSubscribeProjectService;

    /**
     * 查询体检套餐列表
     * @response {@link HospitalSubscribeSetMeal}
     */
    @GetMapping("/list")
    public TableDataInfo list(HospitalSubscribeSetMeal hospitalSubscribeSetMeal)
    {
        startPage();
        List<HospitalSubscribeSetMeal> list = hospitalSubscribeSetMealService.selectHospitalSubscribeSetMealList(hospitalSubscribeSetMeal);
        return getDataTable(list);
    }

    /**
     * 导出体检套餐列表
     */
    @Log(title = "体检套餐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HospitalSubscribeSetMeal hospitalSubscribeSetMeal)
    {
        List<HospitalSubscribeSetMeal> list = hospitalSubscribeSetMealService.selectHospitalSubscribeSetMealList(hospitalSubscribeSetMeal);
        ExcelUtil<HospitalSubscribeSetMeal> util = new ExcelUtil<HospitalSubscribeSetMeal>(HospitalSubscribeSetMeal.class);
        util.exportExcel(response, list, "体检套餐数据");
    }

    /**
     * 获取体检套餐详细信息
     * @response {@link HospitalSubscribeSetMeal}
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        HospitalSubscribeSetMeal hospitalSubscribeSetMeal = hospitalSubscribeSetMealService.selectHospitalSubscribeSetMealById(id);
        String projectIds = hospitalSubscribeSetMeal.getProjectIds();
        String[] ids = projectIds.split(",");
        List<HospitalSubscribeProject> projects = iHospitalSubscribeProjectService.getHospitalSubscribeProjectByIds(Arrays.stream(ids).collect(Collectors.toList()));
        hospitalSubscribeSetMeal.setProjectList(projects);
        return success(hospitalSubscribeSetMeal);
    }

    /**
     * 新增体检套餐
     */
    @Log(title = "体检套餐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalSubscribeSetMeal hospitalSubscribeSetMeal)
    {
        return toAjax(hospitalSubscribeSetMealService.insertHospitalSubscribeSetMeal(hospitalSubscribeSetMeal));
    }

    /**
     * 修改体检套餐
     */
    @Log(title = "体检套餐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalSubscribeSetMeal hospitalSubscribeSetMeal)
    {
        return toAjax(hospitalSubscribeSetMealService.updateHospitalSubscribeSetMeal(hospitalSubscribeSetMeal));
    }

    /**
     * 删除体检套餐
     */
    @Log(title = "体检套餐", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hospitalSubscribeSetMealService.deleteHospitalSubscribeSetMealByIds(ids));
    }
}
